package main

import (
	"context"
	"fmt"
	"github.com/elastic/go-elasticsearch/v8/typedapi/indices/create"
	"github.com/elastic/go-elasticsearch/v8/typedapi/types"
	"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
	"s13_elastic/es"
)

/*
获取APIKey
POST /_security/api_key

	{
	  "name": "filebeat"
	}
*/
func main() {
	client := es.GetClient()
	//create.CreateIndex(client, "my_index2")
	result, _ := client.Search().Index("kubernetes.container-system.container").Query(&types.Query{
		//MatchAll: &types.MatchAllQuery{},
		Match: map[string]types.MatchQuery{
			"message": {Query: "time"},
		},
	}).
		Sort(types.SortOptions{SortOptions: map[string]types.FieldSort{"dd": {Order: &sortorder.SortOrder{Name: "desc"}}}}).
		Do(context.Background())
	fmt.Println(result.Hits.Total.Value)

	client.Indices.Create("kubernetes.container-system.container").Request(&create.Request{
		Aliases: map[string]types.Alias{},
	})
}
